package br.com.esporte.negocios.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

import br.com.esporte.negocios.entidade.util.HoraEnum;
import br.com.esporte.negocios.entidade.util.MinutoEnum;

public class Util {

	public static Date converterDataHora(Date date, HoraEnum hora, MinutoEnum minuto){
		Date data = null;
		try {
			Calendar calendar = Calendar.getInstance();
			calendar.setTime(date);
			StringBuilder dataString = new StringBuilder();
			dataString.append(calendar.get(Calendar.DAY_OF_MONTH));
			dataString.append("/");
			dataString.append(calendar.get(Calendar.MONTH) + 1);
			dataString.append("/");
			dataString.append(calendar.get(Calendar.YEAR));
			dataString.append(" ");

			int horaValor = hora.getValor();
			if(horaValor >= 10){
				dataString.append(horaValor);
			}else{
				dataString.append("0" + horaValor);
			}

			dataString.append(":");

			int minutoValor = minuto.getValor();
			if(minutoValor >= 10){
				dataString.append(minutoValor);
			}else{
				dataString.append("0" + minutoValor);
			}

			SimpleDateFormat dataFormat = new SimpleDateFormat("dd/MM/yyyy hh:mm");


			data = dataFormat.parse(dataString.toString());
		} catch (Exception e) {

		}
		return data;
	}

	public static String converterDataHoraToString(Date date){
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(date);
		StringBuilder dataString = new StringBuilder();
		dataString.append(calendar.get(Calendar.DAY_OF_MONTH));
		dataString.append("/");
		dataString.append(calendar.get(Calendar.MONTH) + 1);
		dataString.append("/");
		dataString.append(calendar.get(Calendar.YEAR));
		dataString.append(" ");
		dataString.append(calendar.get(Calendar.HOUR));
		dataString.append(":");
		dataString.append(calendar.get(Calendar.MINUTE));

		return dataString.toString();
	}

	public static String converterDataToString(Date date){
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(date);
		StringBuilder dataString = new StringBuilder();
		dataString.append(calendar.get(Calendar.DAY_OF_MONTH));
		dataString.append("/");
		dataString.append(calendar.get(Calendar.MONTH) + 1);
		dataString.append("/");
		dataString.append(calendar.get(Calendar.YEAR));
		return dataString.toString();
	}

	public static String converterHoraToString(Date date){
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(date);
		StringBuilder dataString = new StringBuilder();
		dataString.append(calendar.get(Calendar.HOUR));
		dataString.append(":");
		dataString.append(calendar.get(Calendar.MINUTE));

		return dataString.toString();
	}

	public static Date converterStringToData(String dataString){
		SimpleDateFormat dataFormat = new SimpleDateFormat("dd/MM/yyyy hh:mm");
		Date data = null;
		try {
			data = dataFormat.parse(dataString);
		} catch (ParseException e) {

		}
		return data;
	}

	public static boolean isNull(String obj){
		return ((obj == null) || obj.trim().equals(""));
	}

}
